home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
Cheat II
/
cheatrick.cold
< prev
next >
Wrap
Text File
|
1996-01-05
|
4KB
|
204 lines
// cheatrick.c
// all the trap patch shit
#include "cheatrick.h"
#include "cheatWindow.h"
#include "main.h"
#include "cheat.h"
#include "ResRefs.h"
#include "cheat.h"
#include "cheatwich.h"
#include "pascal.h"
#include <string.h>
#include "error.h"
#include "Timer.h"
#include "Processes.h"
#define commandkey 0x37
#define optionkey 0x3A
#define controlkey 0x3B
// used for saving and restoring registers
#define setupcode() asm {\
movem.l a0-a5/D0-D7, -(SP)\
}
#define cleanupcode() asm {\
movem.l (SP)+, a0-a5/D0-D7\
}
static long oldtrap;
unsigned char km[16];
// k = any keyboard scan code, 0-127
static int isPressed(unsigned short k )
{
return ( ( km[k>>3] >> (k & 7) ) & 1);
}
pascal void myGetKeys(KeyMap theKeys)
{
long oura5;
GDHandle SaveGD;
CGrafPtr SavePort;
setupcode();
oura5 = SetCurrentA5();
CallPascal(theKeys, oldtrap);
/* asm{
move.l theKeys, km
} */
// my sneaky asm code doesn't seem to work, so . . .
*((long *)&km[0]) = theKeys[0];
*((long *)&km[4]) = theKeys[1];
*((long *)&km[8]) = theKeys[2];
*((long *)&km[12]) = theKeys[3];
if (isPressed(controlkey) && isPressed(commandkey) && isPressed(optionkey)) {
// they've hit the key combo to enter our program
// GetGWorld(&SavePort, &SaveGD);
SysBeep(1);
}
cleanupcode();
}
void doInstallTrap(void)
{
oldtrap = GetToolTrapAddress(0x176);
verify(oldtrap);
SetToolTrapAddress((long) myGetKeys, 0x176);
}
void doRemoveTrap(void)
{
SetToolTrapAddress(oldtrap, 0x176);
}
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
static void
__GetA5(void)
{
asm {
bsr.s @1
dc.l 0 ; store A4 here
@1 move.l (sp)+,a1
}
}
#define RememberA5() do { __GetA5(); asm { move.l a5,(a1) } } while (0)
#define RecallA5() do { __GetA5(); asm { move.l (a1),a5 } } while (0)
pascal void newGetKeys(KeyMap theKeys)
{
long oura5;
setupcode();
RecallA5();
CallPascal(theKeys, oldtrap);
/* asm{
move.l theKeys, km
} */
// my sneaky asm code doesn't seem to work, so . . .
*((long *)&km[0]) = theKeys[0];
*((long *)&km[4]) = theKeys[1];
*((long *)&km[8]) = theKeys[2];
*((long *)&km[12]) = theKeys[3];
if (isPressed(controlkey) && isPressed(commandkey) && isPressed(optionkey)) {
// they've hit the key combo to enter our program
if (!cheatwich(oldtrap))
SysBeep(1);
}
cleanupcode();
}
typedef struct {
struct TMTask atm;
long tmWakeUp;
long tmReserved;
long tmRefCon;
} mytminfo;
mytminfo tmi;
long del = 4000;
// our delightful time manager task
pascal void mytask(void)
{
mytminfo *rec;
long oldA5;
long newdelay;
ProcessSerialNumber psn;
OSErr err;
int i, newone;
Boolean res;
// get our data
asm {
move.l A1, rec\
}
setupcode();
oldA5 = SetA5(rec->tmRefCon);
err = GetFrontProcess(&psn);
newone = false;
if (!err) {
newone = true; // assume unique
// check if it's our app specially
err = SameProcess(&psn, &usPSN, &res);
if (!err && res)
newone = false; // it's Cheat itself
else
for (i=0;i<numProcs;i++) {
err = SameProcess(&psn, &InfoRec[i].processNumber, &res);
if (!err && res)
newone = false; // already found
}
if (newone) {
// patch the trap
SetToolTrapAddress((long) newGetKeys, 0x176);
}
}
if (!newone) { // install it again and wait
newdelay = 4000;
PrimeTime((QElemPtr) rec, newdelay);
} // else we have patched one thing, that's enough for today
cleanupcode();
}
// put the task in the queue
void installTMTask(void)
{
RememberA5(); // used in trap patch
shouldclearup = false;
// used for getting key stuff, needs to be changed eventually
oldtrap = GetToolTrapAddress(0x176);
verify(oldtrap);
tmi.atm.tmAddr = (void *) mytask;
tmi.tmWakeUp = 0;
tmi.tmReserved = 0;
tmi.tmRefCon = SetCurrentA5();
InsTime((QElemPtr) &tmi);
PrimeTime((QElemPtr) &tmi, del);
}
void removeTMTask(void)
{
RmvTime((QElemPtr) &tmi);
}